package jgrit.control;

import java.io.IOException;

import jgrit.options.OptionCollection;

/**
 * Acts as a large switch to determine the proper service to call
 * @author Taylor Perkins, Derek Olejnik
 */
public class ExportService {
	/**
	 * Performs the requested export operation.
	 * 
	 * @return the output from the operation.
	 */
	public static String executeCommand(OptionCollection userOptions) throws ExportException {		
		String consoleOutput;
		
		ImageService chosenService = chooseService(userOptions);
		if (chosenService == ImageService.GRIT) {
			GritService gritService = new GritService(userOptions);
			consoleOutput = gritService.executeCommand();
		}
		/*
		 * NOTE: The following is the format you would use to call a different
		 * binary (if it is to be added in the future)
		 */
		//else if (chosenService == ImageService.GFX2GBA) {
		//	Gfx2GbaService gfxService = new Gfx2GbaService(userOptions);
		//	consoleOutput = gfxService.executeCommand();
		//}
		else {
			throw new AssertionError("chosen service not recognized: " + chosenService);
		}
		
		return consoleOutput;
	}
	
	private static ImageService chooseService(OptionCollection options) {
		
		if (options.sourceFiles.size() == 1) {
			return ImageService.GRIT;
		}
		else if (options.sourceFiles.size() > 1) {
			return ImageService.GFX2GBA;
		}
		
		return ImageService.NONE;
	}
	
	enum ImageService { GRIT, GFX2GBA, NONE; }
}
